package com.csproj.system.domain;

import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;


/**
 * A UserInfo.
 */
@Entity
@Table(name = "sys_user_info")
@EntityListeners(AuditingEntityListener.class)
public class UserInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @Column(name = "id")
    private String id;

    @Column(name="name")
    private String name;            //姓名

    @Column(name="account")
    private String account;         //帐号

    @Column(name="jhi_password")
    private String password;        //密码

    @Column(name="code")
    private String code;            //用户编号

    @Column(name="used_flag")
    private Boolean usedFlag;         //是否停用



    @Column(name="remark")
    private String remark;

    @Column(name="type")
    private Integer type;

    @Column(name="site_id")
    private String siteId;

    @Column(name="site_name")
    private String siteName;

    @Column(name="phone")
    private String phone;           //电话

    @Column(name = "deleted_flag")
    private Boolean deletedFlag;

    @ManyToMany
    @JoinTable(name = "sys_user_info_role_info",
            joinColumns = @JoinColumn(name="user_infos_id", referencedColumnName="id"),
            inverseJoinColumns = @JoinColumn(name="role_infos_id", referencedColumnName="id"))
    private Set<RoleInfo> roleInfos = new HashSet<>();


    public Set<RoleInfo> getRoleInfos() {
        return roleInfos;
    }

    public UserInfo roleInfos(Set<RoleInfo> roleInfos) {
        this.roleInfos = roleInfos;
        return this;
    }

    public UserInfo addRoleInfo(RoleInfo roleInfo) {
        this.roleInfos.add(roleInfo);
        roleInfo.getUserInfos().add(this);
        return this;
    }

    public UserInfo removeRoleInfo(RoleInfo roleInfo) {
        this.roleInfos.remove(roleInfo);
        roleInfo.getUserInfos().remove(this);
        return this;
    }

    public void setRoleInfos(Set<RoleInfo> roleInfos) {
        this.roleInfos = roleInfos;
    }

    /**
     * 删除人
     */
    @ApiModelProperty(value = "删除人")
    @Column(name = "deleter_user_id")
    private String deleterUserId;

    /**
     * 删除时间
     */
    @ApiModelProperty(value = "删除时间")
    @Column(name = "deletion_time")
    private ZonedDateTime deletionTime;

    /**
     * 最近更新时间
     */
    @LastModifiedDate
    @ApiModelProperty(value = "最近更新时间")
    @Column(name = "last_modification_time")
    private ZonedDateTime lastModificationTime;

    /**
     * 最近更新人
     */
    @LastModifiedBy
    @ApiModelProperty(value = "最近更新人")
    @Column(name = "last_modifier_user_id")
    private String lastModifierUserId;

    /**
     * 创建时间
     */
    @CreatedDate
    @ApiModelProperty(value = "创建时间")
    @Column(name = "creation_time")
    private ZonedDateTime creationTime;

    /**
     * 创建人
     */
    @CreatedBy
    @ApiModelProperty(value = "创建人")
    @Column(name = "creator_user_id")
    private String creatorUserId;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Boolean getUsedFlag() {
        return usedFlag;
    }

    public void setUsedFlag(Boolean usedFlag) {
        this.usedFlag = usedFlag;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Boolean getDeletedFlag() {
        return deletedFlag;
    }

    public void setDeletedFlag(Boolean deletedFlag) {
        this.deletedFlag = deletedFlag;
    }

    public String getDeleterUserId() {
        return deleterUserId;
    }

    public void setDeleterUserId(String deleterUserId) {
        this.deleterUserId = deleterUserId;
    }

    public ZonedDateTime getDeletionTime() {
        return deletionTime;
    }

    public void setDeletionTime(ZonedDateTime deletionTime) {
        this.deletionTime = deletionTime;
    }

    public ZonedDateTime getLastModificationTime() {
        return lastModificationTime;
    }

    public void setLastModificationTime(ZonedDateTime lastModificationTime) {
        this.lastModificationTime = lastModificationTime;
    }

    public String getLastModifierUserId() {
        return lastModifierUserId;
    }

    public void setLastModifierUserId(String lastModifierUserId) {
        this.lastModifierUserId = lastModifierUserId;
    }

    public ZonedDateTime getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(ZonedDateTime creationTime) {
        this.creationTime = creationTime;
    }

    public String getCreatorUserId() {
        return creatorUserId;
    }

    public void setCreatorUserId(String creatorUserId) {
        this.creatorUserId = creatorUserId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserInfo userInfo = (UserInfo) o;
        return Objects.equals(id, userInfo.id) &&
                Objects.equals(name, userInfo.name) &&
                Objects.equals(account, userInfo.account) &&
                Objects.equals(password, userInfo.password) &&
                Objects.equals(code, userInfo.code) &&
                Objects.equals(usedFlag, userInfo.usedFlag) &&
                Objects.equals(type, userInfo.type) &&
                Objects.equals(phone, userInfo.phone) &&
                Objects.equals(deletedFlag, userInfo.deletedFlag) &&
                Objects.equals(deleterUserId, userInfo.deleterUserId) &&
                Objects.equals(deletionTime, userInfo.deletionTime) &&
                Objects.equals(lastModificationTime, userInfo.lastModificationTime) &&
                Objects.equals(lastModifierUserId, userInfo.lastModifierUserId) &&
                Objects.equals(creationTime, userInfo.creationTime) &&
                Objects.equals(creatorUserId, userInfo.creatorUserId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, account, password, code, usedFlag, type, phone, deletedFlag, deleterUserId, deletionTime, lastModificationTime, lastModifierUserId, creationTime, creatorUserId);
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", account='" + account + '\'' +
                ", password='" + password + '\'' +
                ", code='" + code + '\'' +
                ", usedFlag=" + usedFlag +
                ", type=" + type +
                ", phone='" + phone + '\'' +
                ", deletedFlag=" + deletedFlag +
                ", deleterUserId='" + deleterUserId + '\'' +
                ", deletionTime=" + deletionTime +
                ", lastModificationTime=" + lastModificationTime +
                ", lastModifierUserId='" + lastModifierUserId + '\'' +
                ", creationTime=" + creationTime +
                ", creatorUserId='" + creatorUserId + '\'' +
                '}';
    }

    public String getSiteId() {
        return siteId;
    }

    public void setSiteId(String siteId) {
        this.siteId = siteId;
    }

    public String getSiteName() {
        return siteName;
    }

    public void setSiteName(String siteName) {
        this.siteName = siteName;
    }
}
